//
//  FLMTabBarController.m
//  FLMSuperS
//
//  Created by xiaoyang on 16/9/6.
//  Copyright © 2016年 FaLaoMiaoNetworkTechnologyCo. All rights reserved.
//

#import "FLMTabBarController.h"
#import "FLMNavigationController.h"

#import "FLMHomeVC.h"
#import "FLMMessageController.h"
#import "FLMExchangeViewController.h"
#import "FLMTaskViewController.h"

@interface FLMTabBarController ()

@end

@implementation FLMTabBarController

+(void)load
{
    //获取全局TabBarItem
    UITabBarItem *barItem = [UITabBarItem appearanceWhenContainedIn:self, nil];
    
    //设置正常的字体->字体的大小跟normal有关
    NSMutableDictionary *attTitle = [NSMutableDictionary dictionary];
    //设置字体大小
    attTitle[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    [barItem setTitleTextAttributes:attTitle forState:UIControlStateNormal];
    
    
    //设置选中的字体
    NSMutableDictionary *selelTitle = [NSMutableDictionary dictionary];
    selelTitle[NSForegroundColorAttributeName] = [UIColor blackColor];
    [barItem setTitleTextAttributes:selelTitle forState:UIControlStateSelected];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];

    //设置子控制器
    [self setAddChildViewController];
}



#pragma mark --------------------
#pragma mark 添加四个模块控制器
- (void)setAddChildViewController
{
    //首页
     [self setupChildVc:[[FLMHomeVC alloc] init] title:@"首页" image:[UIImage imageNamed:@"home_default"] selectedImage:[UIImage imageNamed:@"home_hightLight"]];
    
    //消息
    [self setupChildVc:[[FLMMessageController alloc] init] title:@"消息" image:[UIImage imageNamed:@"message_default"] selectedImage:[UIImage imageNamed:@"message_hightLight"]];
    
    /*
    //任务
    [self setupChildVc:[[FLMTaskViewController alloc] init] title:@"任务" image:[UIImage imageNamed:@"task_default"] selectedImage:[UIImage imageNamed:@"task_hightLight"]];
     */
    
    //兑换
    [self setupChildVc:[[FLMExchangeViewController alloc] init] title:@"个人中心" image:[UIImage imageNamed:@"exchange_default"] selectedImage:[UIImage imageNamed:@"exchange_hightLight"]];
}

#pragma mark --------------------
#pragma mark 设置子控制器的属性
- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectedImage
{
    
    //设置文字和图片
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //添加子控制器
    [self addChildViewController:vc];
    
    //设置导航栏的背景色字体大小,这些属性,都是导航控制器的,所以这些应该放到导航控制器内部
    FLMNavigationController *nav = [[FLMNavigationController alloc] initWithRootViewController:vc];
    
    //设置文字的样式
    NSMutableDictionary *textAttr = [NSMutableDictionary dictionary];
    textAttr[NSForegroundColorAttributeName] = FLMColor_RGB(123, 124, 123);
    
    NSMutableDictionary *selectedAttr = [NSMutableDictionary dictionary];
    selectedAttr[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    [vc.tabBarItem setTitleTextAttributes:textAttr forState:UIControlStateNormal];
    [vc.tabBarItem setTitleTextAttributes:selectedAttr forState:UIControlStateSelected];
    
    [self addChildViewController:nav];
}



@end
